package com.eastrobot.doc.poitlconvert.util;

import com.deepoove.poi.data.ChartMultiSeriesRenderData;
import com.deepoove.poi.data.Charts;
import com.deepoove.poi.data.SeriesRenderData;
import com.eastrobot.doc.poitlconvert.entity.mytemplateEntity.ChartDataModel;
import org.apache.commons.collections4.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class ChartUtil {
    public static ChartMultiSeriesRenderData dealChart(){

        List<SeriesRenderData> seriesRenderData = new ArrayList<SeriesRenderData>(3);
        SeriesRenderData series1 = new SeriesRenderData("GDP", new Double[] {70.5,40.6,22.7,85.4,700.0,40.8});
        series1.setComboType(SeriesRenderData.ComboType.BAR);
        seriesRenderData.add(series1);
        SeriesRenderData series2 = new SeriesRenderData("人口", new Double[] {80.5,50.6,62.7,45.4,200.0,140.8});
        series2.setComboType(SeriesRenderData.ComboType.BAR);
        seriesRenderData.add(series2);
        SeriesRenderData series3 = new SeriesRenderData("指数", new Double[] {0.6,0.6,0.7,0.4,0.7,0.8});
        series3.setComboType(SeriesRenderData.ComboType.LINE);
        seriesRenderData.add(series3);

        ChartMultiSeriesRenderData hntb = Charts
                .ofMultiSeries("某省社会排名", new String[] { "城市1","城市2","城市3","城市4","城市5","城市6"})
                .create();
        hntb.setSeriesDatas(seriesRenderData);
        return hntb;
    }



    public static ChartMultiSeriesRenderData dealchartSimple(List<ChartDataModel> dataList)  {
        // 构建图表模型
        ChartMultiSeriesRenderData chart = null;
        if (!CollectionUtils.isEmpty(dataList)){
            chart = Charts
                    .ofMultiSeries("mychart", dataList.stream()
                            .map(ChartDataModel::getDataName)
                            .collect(Collectors.toList())
                            .toArray(new String[dataList.size()]))
                    .addSeries("countries", dataList.stream()
                            .map(ChartDataModel::getDataValue)
                            .collect(Collectors.toList())
                            .toArray(new Long[dataList.size()]))
                    .addSeries("speakers", dataList.stream()
                            .map(ChartDataModel::getLastDataValue)
                            .collect(Collectors.toList())
                            .toArray(new Long[dataList.size()]))
                    .create();
        }

        return chart;
//        作者：牛客492812512号
//        链接：https://www.nowcoder.com/discuss/521386400126631936
//        来源：牛客网
    }
}
